#pragma once

#include <string>
#include <memory>
#include <fstream>
#include <vector>
#include "LogLayout.h"
#include "LogEvent.h"

namespace log
{

class LogAppender
{
public:
    using ptr = std::shared_ptr<LogAppender>; 

    LogAppender() {}
    virtual ~LogAppender() {}
    virtual void append(const std::string& strLog) = 0;
    virtual void append(const LogEvent::ptr ptrEvent);
    virtual void setLayout(LogLayout::ptr ptrLayout) { m_ptrLayout = ptrLayout; }

protected:
    LogLayout::ptr m_ptrLayout;
};
 
class FileAppender : public LogAppender
{
public:
    using ptr = std::shared_ptr<FileAppender>; 

    FileAppender(const std::string& strFile);
    virtual ~FileAppender() override;
    bool open(const std::string& strFile);
    void close();
    virtual void append(const std::string& strLog) override;
    void setFileMaxSize(size_t n) { m_nMaxSize = n; }
    void setFileMaxSize(const std::string& n);

private:
    std::ofstream m_ofstream;
    std::string m_strFile;
    size_t m_nMaxSize;
    size_t m_nCurrSize;
};
 
class StdoutAppender : public LogAppender
{
public:
    using ptr = std::shared_ptr<StdoutAppender>;

    StdoutAppender() {}
    virtual ~StdoutAppender() {}
    virtual void append(const std::string& strLog) override;
};



    
} // namespace log
